//
//  UIImage+ExBase64.m
//  OC-Example
//
//  Created by lcj on 2020/11/3.
//  Copyright © 2020 apang.men. All rights reserved.
//

#import "UIImage+ExBase64.h"
#import <Foundation/Foundation.h>

@implementation UIImage (ExBase64)
- (NSString *)apm_encodeToBase64String:(CGFloat)compressionQuality{
    if(compressionQuality <= 0) compressionQuality = 1.0;
    if(compressionQuality >= 1) compressionQuality = 1.0;
    NSData * data = UIImageJPEGRepresentation(self, compressionQuality);
    return [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}

+ (nullable UIImage *)apm_decodeBase64:(NSString *)string {
    if (string.length>0) {
        NSData *data = [[NSData alloc]initWithBase64EncodedString:string options:NSDataBase64DecodingIgnoreUnknownCharacters];
        if (data.length>0) {
            return [UIImage imageWithData:data];
        }
    }
    return nil;
}
@end
